
public class Mem_Ctr {
	int AccMem;
	int ALU_OUT;
	int MemData;
	int AddMem;
	int MemWE;
	Memory mem;
	
	int memDIn_Sel;
	int wb_prev;
	
	int DataVal;
	
	void init(Memory memory){
		AccMem=0;
		MemWE=0;
		ALU_OUT=0;
		mem=memory;
	}
	void set_AccMem(int regwe){
		AccMem=regwe;
	}
	void set_ALU_Out(int regwe){
		ALU_OUT=regwe;
	}
	void set_MemData(int regwe){
		MemData=regwe;
	}
	void set_AddMem(int regwe){
		AddMem=regwe;
	}
	void set_MemWE(int regwe){
		MemWE=regwe;
	}
	void go(){
		if(memDIn_Sel==1){
			MemData=wb_prev;
		}
		
		
		if(AccMem!=1){
			DataVal=ALU_OUT;
		}else{
			if(MemWE==1){
				mem.putWord(ALU_OUT, MemData);
				DataVal=0;
			}else{
				DataVal=mem.getWord(ALU_OUT);
			}
		}
	}
	int get_DataVal(){	
		return DataVal;
	}
	
}
